import { APP_ROUTER_CONFIG } from "@/config";
import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";
import { useGuard } from "./guard";
import { routes } from "./modules";
import { flatRoutes } from "./config";

export { routes } from "./modules";

export * from "./config";

const router = createRouter({
  history: APP_ROUTER_CONFIG.isHash
    ? createWebHashHistory()
    : createWebHistory(APP_ROUTER_CONFIG.basePath),
  routes: flatRoutes(routes),
  scrollBehavior() {
    return {
      top: 0,
      left: 0,
    };
  },
});

// 全局导航守卫统一处理
useGuard(router);

export default router;
